/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager;

import com.etfbl.net.dao.*;
import com.etfbl.net.dto.*;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.etfbl.dao.base.IDAOBase;

/**
 *
 * @author Aleksandar
 */
public class EntityManager {

    private Map<Class, IDAOBase> map = new HashMap<Class, IDAOBase>();
    private static EntityManager entityManager;
    
    public static EntityManager getEntityManager() {
        if(entityManager == null)
            entityManager = new EntityManager();
        return entityManager;
    }

    private EntityManager() {
        map.put(Drzava.class, new DAODrzava());
//        map.put(Event.class, new DAOEvent());
        map.put(Mjesto.class, new DAOMjesto());
//        map.put(User.class, new DAOUser());
    }
    
    // Find by primary key.
    public <T> T find(Class<T> entityClass, Object primaryKey) {
        return (T) map.get(entityClass).find((Serializable) primaryKey);
    }
    
    public <T> List<T> findAll(Class<T> entityClass) {
        return map.get(entityClass).findAll();
    }
    
    public <T> T getFirst(Class<T> entityClass) {
        return (T) map.get(entityClass).getFirst();
    }
    
    public <T> T getLast(Class<T> entityClass) {
        return (T) map.get(entityClass).getLast();
    }
    
    public <T> List<T> query(Class<T> entityClass, String prepareSQL) {
        return map.get(entityClass).query(prepareSQL);
    }
    
    public <T> List<T> query(Class<T> entityClass, String prepareSQL, Object... parameter) {
        return map.get(entityClass).query(prepareSQL, parameter);
    }
    
    public <T> boolean remove(Class<T> entityClass, T entity) {
        return map.get(entityClass).remove(entity);
    }
    
    public <T> boolean save(Class<T> entityClass, T entity) {
        return map.get(entityClass).save(entity);
    }
    
    public <T> boolean save(Class<T> entityClass, List<T> entitys) {
        return map.get(entityClass).save(entitys);
    }
    
    public <T> boolean update(Class<T> entityClass, T entity) {
        return map.get(entityClass).update(entity);
    }
    
    public <T> ResultSet selectResultSet(Class<T> entityClass, String prepareSQL) {
        return map.get(entityClass).selectResultSet(prepareSQL);
    }
    
    public <T> ResultSet selectResultSet(Class<T> entityClass, String prepareSQL, Object... parameter) {
        return map.get(entityClass).selectResultSet(prepareSQL, parameter);
    }
}
